/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.services.saving;

import java.io.Serializable;
import org.hibernate.Query;
import org.hibernate.Session;
import src.HibernateUtil;
import src.domain.saving.Savconfig;
import src.services.CRUEDService;

/**
 *
 * @author Lalugina
 */
public class SavconfigModel implements Serializable {
    
    Session session;
    private CRUEDService service;
    private Savconfig savconfig;
    
    public SavconfigModel() {
        service = new CRUEDService();
    }

    public Savconfig getSavconfig() {
        
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
	
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery ("from Savconfig");
            savconfig = (Savconfig) q.uniqueResult();
            
            tx.commit();
        } catch (Exception e) {}
        
        return savconfig;
    }

    public void setSavconfig(Savconfig savconfig) {
        this.savconfig = savconfig;
    }
    
    public boolean saveData(Savconfig data, boolean editMode) {
        if (editMode) return service.updateData(data);
        else return service.saveOnly(data);
    }
}
